package com.joysuch.wwyt.bp.controller;

import com.joysuch.wwyt.bp.bean.risk.BpDepartBean;
import com.joysuch.wwyt.bp.bean.risk.BpDepartDto;
import com.joysuch.wwyt.bp.bean.risk.BpRiskDepartReportDto;
import com.joysuch.wwyt.bp.entity.BpDepart;
import com.joysuch.wwyt.bp.entity.risk.BpTeam;
import com.joysuch.wwyt.bp.service.BpRiskDepartService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;

/**
 * @Author ZhangDong
 * @Date 2020/3/6 11:45
 */
@RestController
@RequestMapping("/bp/risk/depart")
@Api(tags = "/bp/risk/depart 风险研判-部门级")
@CrossOrigin
public class BpRiskDepartController {

    @Autowired
    private BpRiskDepartService bpRiskDepartService;

    @PostMapping("save")
    @RequiresPermissions("bp:risk:depart:save")
    @ApiOperation(value = "上报/修改")
    public ResultBean save(@RequestBody @Valid BpDepartBean bpDepartBean) {
        return bpRiskDepartService.save(bpDepartBean);
    }

    @GetMapping("get/{id}")
    @ApiOperation(value = "根据id查询单条数据 & 审批", response = BpDepartDto.class)
    public ResultBean getById(@PathVariable Long id) {
        return bpRiskDepartService.getById(id);
    }

    @GetMapping("page")
    @ApiOperation(value = "分页查询 reportDate: 上报日期  -- flag: 0 部门级; 1 部门级审核", response = BpTeam.class)
    public ResultBean page(Pageable pageable, @RequestParam(value = "reportDate", required = false) LocalDate reportDate,
                           @RequestParam(value = "flag") Integer flag) {
        return bpRiskDepartService.page(pageable, reportDate, flag);
    }

    @GetMapping("submit/{id}")
    @RequiresPermissions("bp:risk:depart:submit")
    @ApiOperation(value = "提交")
    public ResultBean submit(@PathVariable Long id) {
        return bpRiskDepartService.submit(id);
    }

    @GetMapping("delete/{id}")
    @RequiresPermissions("bp:risk:depart:delete")
    @ApiOperation(value = "删除")
    public ResultBean delete(@PathVariable Long id) {
        return bpRiskDepartService.delete(id);
    }

    @GetMapping("verify/{id}/{flag}")
    @RequiresPermissions("bp:risk:depart:verify")
    @ApiOperation(value = "审核通过/不通过 flag: 0 不通过; 1 通过")
    public ResultBean delete(@PathVariable Long id, @PathVariable int flag) {
        return bpRiskDepartService.verify(id, flag);
    }

    @GetMapping("getDepart")
    @ApiOperation(value = "获取自己所在部门", response = BpDepart.class)
    public ResultBean getDepart() {
        return bpRiskDepartService.getDepart();
    }

    @GetMapping("getUser")
    @ApiOperation(value = "获取当前用户信息", response = BpDepart.class)
    public ResultBean getUser() {
        return bpRiskDepartService.getUser();
    }

    @GetMapping("reportPage")
    @ApiOperation(value = "点上报时查询的关于班组的内容(包含特殊作业和班组上报材料)", response = BpRiskDepartReportDto.class)
    public ResultBean reportPage(Pageable pageable) {
        return bpRiskDepartService.reportPage(pageable);
    }
}
